package easy.netty.net.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;

/**
 * @author cengy
 */
public class Starter
        extends Session
        implements CommandLineRunner {

    private static final Logger
            logger = LoggerFactory.getLogger(Starter.class);
    @Autowired
    protected IoCfg ioCfg;

    @Override
    public void run(String... args) throws Exception {
        start(this.getClass().getName());
    }

    public void start(String className) throws Exception {
        if (null == className ||
                className.isEmpty())
            throw new IllegalArgumentException("the parameter named className is null");

        IoConf netConf = ioCfg.getConf(className);
        if (null == netConf) {
            logger.warn("the netConf is empty, named {}", className);
        } else {
            if (netConf.isEnable()) {
                setIoConf(netConf);
                open();
            }
        }
    }
}
